<?php
/*
Template Name: 专题页
 */
    get_header();
    setPostViews(get_the_ID()); 
    $banner_cat = get_post_meta($post->ID, "banner_cat");
    $news_cat = get_post_meta($post->ID, "news_cat");    
?>
<!-- banner图 -->
<div class="banner">
    <div class="swiper-container banner swiper-banner">
        <div class="swiper-wrapper">
            <?php
                //分类5: 首页->banner
                query_posts(array(
                    "showposts"=>5,
                    "cat"=>$banner_cat
                ));
                while ( have_posts()) {
                    the_post();
            ?>
            <div class="swiper-slide banner-slide">
                <a href="<?php the_permalink(); ?>">
                    <span><?php the_title(); ?></span>
                    <span class="hide-img" style="display: none;"><?php the_post_thumbnail( 'full' ); ?></span>
                </a>
            </div>
            <?php 
                }
                wp_reset_query();
            ?>
        </div>
        <div class="banner-pagination"></div>
    </div>
</div>
<!-- /banner图 -->
<!-- 列表模块 -->
<div class="main-container">
    <div class="wrap">
        <div class="clearfix">
            <div class="main-block">
            <ul class="main-common-list">
                <?php
                    query_posts(array(
                        'showposts'=>15,
                        'offset'=>max( 1, get_query_var('paged') )-1,
                        'cat'=>$news_cat
                    ));
                    while(have_posts()) {
                        the_post();
                ?>
                <li>
                    <a href="<?php the_permalink(); ?>" title=""><?php the_title(); ?></a>
                    <span class="date"><?php the_time('Y-m-d'); ?></span>
                </li>
                <?php
                    }
                    wp_reset_query();
                ?>
            </ul>
                <div class="pagination" id="pagination">
                <?php 
                    $allsearch = new WP_Query(array(
                        'cat'=>$news_cat
                    ));
                    par_pagenavi($allsearch, 25); 
                ?>
                </div>
            </div>
            <div class="sidebar">
                    <div class="notice-mod hot-article-mod floor">
                        <div class="head-type02">
                            <h2>热门文章</h2>
                        </div>
                        <div class="article-main">
                        <?php
                            $queryArg = array(
                                'showposts' => 7,
                                "meta_key" => "post_views_count",
                                "orderby" => "meta_value_num",
                                "order" => "DESC",
                                "cat" => $news_cat
                            );
                            query_posts($queryArg);
                            if (have_posts()) {
                                the_post();
                            
                        ?>
                        <div class="article-first clearfix">
                            <a class="img-block" href="<?php the_permalink(); ?>" title="">
                                <?php the_post_thumbnail(array(120, 73)); ?>
                            </a>
                            <div class="art-right">
                                <h3><a href="<?php the_permalink(); ?>" title=""><?php the_title(); ?></a></h3>
                                <p class="date"><?php the_time('Y-m-d'); ?></p>
                            </div>
                        </div>
                        <?php
                        }
                        ?>
                        <ul>
                            <?php
                            for ($i = 0; $i < 7; $i++) {
                                if (have_posts()) {
                                    the_post();
                                ?>
                            <li>
                                <i></i>
                                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                            </li>
                                <?php
                                } else {
                                    break;
                                }
                            }
                            ?>
                        </ul>
                    </div>
                    </div>
                    <?php get_template_part('template-parts/sidebar-topic', get_post_format()); ?>
                </div>
        </div>
    </div>
</div>
<?php
    get_footer();
?>
<script>
(function() {
    //分页
    var pageTotal = parseInt($('.pagination-total em').text());
    $('.pagination-go').on('click', function() {
        var val = parseInt($(this).siblings('input').val());
        if (isNaN(val) || val < 1 || val > pageTotal) {
            alert('请输入1~' + pageTotal + '之间的页码数');
            return;
        }
        var href = 'http://' + location.host + '/news/page/' + val;
        location.href = href;
    }); 


    //轮播
    $('.banner').find('.swiper-slide a').each(function() {
        var src = $(this).find('.hide-img').find('img').attr('src');
        $(this).css('background', 'url(' + src + ') center no-repeat');
    });
    var mySwiper = $(".swiper-banner").swiper({
        loop: true,
        autoplay: 5000,
        loop: true,
        loopAdditionalSlides: 3,
        pagination: ".banner-pagination",
        paginationClickable: true,
        autoplayDisableOnInteraction: false
        //其他设置
    });
})();
</script>
</body>
</html>